<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑护士排班表</title>
	<#include "/common/resource.ftl">
    <link rel="stylesheet" href="${params.contextPath}/static/plug/layui/css/layui.css">
    <link rel="stylesheet" href="${params.contextPath}/static/css/jquery-ui.min.css">
    <script src="${params.contextPath}/static/js/jquery-ui.min.js"></script>
    <script type="text/javascript">
		$(function () {
            $.ajaxRequest({
                url: '${params.contextPath}/web/room/roomList',
                data: {},
                success: function (data) {
                    if (!data.success) {
                        $.message(data.message);
                        return;
                    }
                    var record = data.data;
                    var floorStr = "<option value=''>请选择</option>";
                    for (var i = 0; i < record.length; i++) {
                        floorStr += "<option value='" + record[i] + "'>"+ record[i] +"楼</option>";
                    }
                    $("#floor").append(floorStr);
                    layui.form.render();
                }
            });
            <#if (params.scheduleDate)??>
                var date = new Date(${params.scheduleDate});
                $("[name='scheduleDate']").val(date.getFullYear() + "-" + ((date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1)) + "-" + date.getDate());
            </#if>

            <#if (params.tag)??>
            $("#username").autocomplete({
                source: function(request, response) {
                    $.ajax({
                        url: "${params.contextPath}/web/user/listAll.json",
                        dataType: "json",
                        data: {
                            name: $("#username").val().trim()
                        },
                        success: function(data) {
                            response($.map(data.data, function(item) {
                                return {
                                    value: item.name,
                                    id: item.id
                                }
                            }));
                        }
                    });

                },
                select: function(e, ui) {
                    $("[name='userId']").val(ui.item.id);
                },
                maxLength: 2
            });
            <#else>
            LocalStorage.registHandler("user_handler_select", function (data) {
                $('input[name="userId"]').val(data.id);
                $('input[name="username"]').val(data.name);
            });
            </#if>

			<#if (params.id)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/nurseSchedule/query.json',
					data: {id: "${params.id}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						for (var key in record) {
							$("[name='" + key + "']").val(record[key]);
						}
                        $("[name='scheduleDate']").val(record.scheduleDateStr);

                        layui.form.render();
					}
				});
			</#if>
            $(".ajax-form").unbind().submit(function () {
                try {
                    var form = $(this);
                    if (!form.valid()) {
                        $.message("验证不通过，无法提交表单");
                        return false;
                    }

                    form.formSubmit({
                        callBack:function (data) {
                            <#if (params.tag)??>
                                history.go(-1);
                                <#else>
                                parent.location.reload();
                            </#if>
                        }
                    });
                } catch (e) {
                    console.log("表单提交错误：" + e);
                }
                return false;
            });
		});
	</script>
    <style>
        .layui-form select {display:none !important;}
    </style>
</head>
<body>
	<div class="ui-form">
		<form class="layui-form ajax-form" action="${params.contextPath}/web/nurseSchedule/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
			<input type="hidden" name="id" value="${params.id}" />
            <#if (params.tag)??>
            <div class="layui-form-item">
                <label class="layui-form-label">护士<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="hidden" name="userId" id="userId" value=""/>
                    <input type="text" id="username" name="username" class="layui-input" autocomplete="off"/>
                </div>
            </div>
            <#else>
			<div class="layui-form-item">
                <label class="layui-form-label">护士<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="hidden" name="userId" />
                    <input type="text" name="username" placeholder="请选择工作人员"
                           p="model:'user',handlerId:'user_handler_select'"
                           class="layui-input single-model-select {required:true}" readonly>
                </div>
            </div>
            </#if>
			<div class="layui-form-item">
                <label class="layui-form-label">排班日期<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <input type="text" name="scheduleDate" placeholder="请输入排班日期" class="layui-input  ui-date {required:true}" readonly/>
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">楼层<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <select lay-filter="floor" id="floor" name="floor" class="layui-input {required:true}">

                    </select>
                </div>
            </div>
			<div class="layui-form-item">
                <label class="layui-form-label">备注<span class="ui-request">*</span></label>
                <div class="layui-input-block">
                    <textarea type="text" name="remark" class="layui-textarea {required:true}" maxlength="500"></textarea>
                </div>
            </div>

			<div class="layui-form-item">
				<div class="layui-input-block">
					<input type="submit" value="保存" class="layui-btn" />
				</div>
			</div>
		</form>
	</div>
</body>
<script src="${params.contextPath}/static/plug/layui/layui.all.js"></script>
</html>
